package com.smcaiot.filesync.starter.controller;

import com.smcaiot.filesync.starter.annotation.ApiPrefix;
import com.smcaiot.filesync.starter.entity.FindNotPullListParams;
import com.smcaiot.filesync.starter.entity.FinishPullParams;
import com.smcaiot.filesync.starter.entity.ReceiveParams;
import com.smcaiot.filesync.starter.service.RemoteService;
import com.smcaiot.filesync.starter.util.RestResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

import static com.smcaiot.filesync.starter.constants.Constants.*;

/**
 * @Author: cz
 * @Date: 2023/6/29
 * @Description:
 */
@RestController
@ApiPrefix
public class RemoteController {

    @Autowired
    private RemoteService remoteService;

    @RequestMapping(value = URL_RECEIVE_FILE, method = RequestMethod.POST)
    public RestResp receiveFile(@Valid @RequestBody ReceiveParams params) {
        String picPath = remoteService.receiveFile(params);
        return RestResp.successRestResp(picPath);
    }

    @RequestMapping(value = URL_FIND_NOT_PULL_LIST, method = RequestMethod.POST)
    public RestResp findNotPullList(@RequestBody FindNotPullListParams params) {
        List list = remoteService.findNotPullList(params);
        return RestResp.successRestResp(list);
    }

    @RequestMapping(value = URL_FINISH_PULL, method = RequestMethod.POST)
    public RestResp finishPull(@RequestBody FinishPullParams params) {
        boolean result = remoteService.finishPull(params);
        return RestResp.successRestResp(result);
    }

}
